# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution(object):
    def partition(self, head, x):
        """
        :type head: ListNode
        :type x: int
        :rtype: ListNode
        """
        less = ListNode(None)
        lessCur = less
        greator = ListNode(None)
        greatorCur = greator
        while head:
            if head.val<x:
                lessCur.next = head
                head = head.next
                lessCur = lessCur.next
                lessCur.next = None
            else:
                greatorCur.next = head
                head = head.next
                greatorCur = greatorCur.next
                greatorCur.next = None
        lessCur.next = greator.next
        return less.next